package com.fourth_groups.shopping121store.ui.category.myfragment;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.fourth_groups.shopping121store.ui.cart.CartFragment;
import com.fourth_groups.shopping121store.ui.category.CategoryFragment;
import com.fourth_groups.shopping121store.ui.home.view.HomeFragment;
import com.fourth_groups.shopping121store.ui.sight.SightFragment;

/**
 * 类名：CategoryFragmentFactory
 * 创建人：ZhangPing
 * 邮箱：zp045217@163.com
 * 创建时间：2016/10/11
 * 备注：
 */

public class CategoryFragmentFactory {
    private static final int FRAGMENT_HOME = 0;
    private static final int FRAGMENT_SHOP = 1;
    private static final int FRAGMENT_SIGHT = 2;
    private static final int FRAGMENT_CART = 3;
    private static SparseArray<Fragment> list = new SparseArray<>();

    public static Fragment setFragment(int key) {
        Fragment fragment = list.get(key);
        if (fragment == null) {
            switch (key) {
                case FRAGMENT_HOME:
                    fragment = HomeFragment.setFragment();
                    break;
                case FRAGMENT_SHOP:
                    fragment = CategoryFragment.setFragment();
                    break;
                case FRAGMENT_SIGHT:
                    fragment = SightFragment.setFragment();
                    break;
                case FRAGMENT_CART:
                    fragment = CartFragment.setFragment();
                    break;
            }
            list.put(key,fragment);
        }
        return fragment;
    }
}
